package org.demo.client;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.demo.domain.person.Person;
import org.demo.domain.response.ResponseEnvelope;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

public class DemoClient {

	public static final String URL_PERSON_FINDALL = "http://localhost:8080/demo-web/rest/private/person/findall";
	public static final String URL_PERSON_GET = "http://localhost:8080/demo-web/rest/private/person/get";
	public static final String URL_PERSON_FIND = "http://localhost:8080/demo-web/rest/private/person/find";
	public static final String URL_PERSON_INSERT = "http://localhost:8080/demo-web/rest/private/person/insert";
	public static final String URL_PERSON_INSERT_ALL = "http://localhost:8080/demo-web/rest/private/person/insertAll";

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		RestTemplate restTemplate = new RestTemplate();

		//Create a list for the message converters

		List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();

		//Add the Jackson Message converter
		messageConverters.add(new MappingJacksonHttpMessageConverter());

		//Add the message converters to the restTemplate
		restTemplate.setMessageConverters(messageConverters);

		ResponseEnvelope<List<Person>> response = restTemplate.getForObject(URL_PERSON_FINDALL, ResponseEnvelope.class);
		System.out.println(response.getResponseHeader().getDate());


		Person person = new Person("Pebbles", "Flinstone");
		List<Person> persons = new ArrayList<Person>();
		for (int i=0; i<10; i++) {
			persons.add(person);
		}
		restTemplate.postForObject(URL_PERSON_INSERT_ALL, persons, Person.class);


	}

}
